import sys

def usage():
	print "Usage:\n%s batch-data-filename display_unknow" % (sys.argv[0])
	
def check_args():
	if len(sys.argv)<3:
		return False
	else:
		return True



		
		
if __name__=="__main__":

	if not check_args():
		usage()
		exit()
	
	try:
		import matplotlib.pyplot as plt
		from mpl_toolkits.mplot3d import Axes3D
	except:
		print "Error: Could not find the matplotlib library on your system."
		print "Please install the matplotlib library for python first:"
		print "\tsudo apt-get install python-matplotlib"
		exit()	
		
	filename=sys.argv[1]
	disp_unknown=int(sys.argv[2])
	try:
		f=open(filename,"r")
		print "Opened file %s for reading" % (filename)
	except:
		print "Error: Could not open the file."
		exit()
	#////////////////////////////////////////////////////////
	
	# EXTRACT DATA
	
	unkown_x=[]
	unkown_y=[]
	unkown_z=[]
	
	pred_x=[]
	pred_y=[]
	pred_z=[]
	
	prey_x=[]
	prey_y=[]
	prey_z=[]
	
	for line in f:
		x,y,z,label=line.split(" ")
		x=int(x)
		y=int(y)
		z=int(z)
		label=int(label)
		
		if label==0:
			unkown_x.append(x)
			unkown_y.append(y)
			unkown_z.append(z)
		elif label==1:
			pred_x.append(x)
			pred_y.append(y)
			pred_z.append(z)
		elif label==2:
			prey_x.append(x)
			prey_y.append(y)
			prey_z.append(z)
			
	# PLOT DATA

    	
	fig = plt.figure()
	ax = Axes3D(fig)

	if not len(unkown_x)==0 and disp_unknown==1:
		ax.scatter(unkown_x, unkown_y, unkown_z, c='b', marker="+")
	if not len(pred_x)==0:
		ax.scatter(pred_x, pred_y,pred_z, c='r', marker="^")
	if not len(prey_x)==0:	
		ax.scatter(prey_x, prey_y,prey_z, c='b', marker="o")

	ax.set_xlabel('Predator Starve time')
	ax.set_ylabel('Predator Breed time')
	ax.set_zlabel('Prey Breed time')
	plt.show()
	#////////////////////////////////////////////////////////	
	f.close()


